{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1、输出5*5矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  1.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  1.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  1.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  1.]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.eye(5)\n",
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2、根据城市人口数量，预测开小吃店的利润 数据在ex1data1.txt里，第一列是城市人口数量，第二列是该城市小吃店利润。\n",
    "* 2.1 Plotting the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Population</th>\n",
       "      <th>Profit</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6.1101</td>\n",
       "      <td>17.5920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5.5277</td>\n",
       "      <td>9.1302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8.5186</td>\n",
       "      <td>13.6620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7.0032</td>\n",
       "      <td>11.8540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.8598</td>\n",
       "      <td>6.8233</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Population   Profit\n",
       "0      6.1101  17.5920\n",
       "1      5.5277   9.1302\n",
       "2      8.5186  13.6620\n",
       "3      7.0032  11.8540\n",
       "4      5.8598   6.8233"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path = \"./data/ex1data1.txt\"\n",
    "data = pd.read_csv(path, header=None, names=['Population', 'Profit'])\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtEAAAHjCAYAAADlk0M8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X+Q3OldH/j309LsaNhZ7GFkfEZjs3GJS85wskgU2yCgjLnjwGcEPqUojCHmQuJQBxS+JCdRUAQDlQsrfl0OHDhjuzB3PkhgMLv2OZcD1vywq2zQGu14/YPYpNbsKIu9DFp7x5FmR+rn/pie9Ug7P/qrmZ5vd8/rVTU1Pd/+9vSjp1s973768zxPqbUGAADoX6ftBgAAwKgRogEAoCEhGgAAGhKiAQCgISEaAAAaEqIBAKAhIRoAABoSogEAoCEhGgAAGjrcdgP6cfTo0Xr33Xe33QwAAMbcAw888Fe11mftdN5IhOi77747Fy9ebLsZAACMuVLKJ/o5TzkHAAA0JEQDAEBDAwvRpZTnllLeX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oB8BYOdx2AwAOoKu11pMbD5RStju/bvHz9XxuMOTIFrf9+SQ/W2u9r5Ty0iSvb9TSp1vpfb8Rf0OAA8xINMBw+KMk31JK+bxSyp1JXtk7liTPK6V8Re/yt2etRCNJHk7yd3qXz27xe5+R5HLv8ms2HH8iyV23nlxr/XSSKxvqnb8zyR/ceh7AQSdEAwyBWusHkvxKkj9O8v4kb6q1/mnv6j9L8r2llI8kmUnyi73jP5bkX5VSLmZtZHgzr0/yG6WUB5L81Ybj70jyyvWJhbfc5jVJfqqUspDkZJIf382/DWAclVpv/ZQQgGHRW0njnb3l8AAYEkaiAQCgISPRAADQkJFoAABoSIgGAICGhGgAAGhIiAYAgIaEaAAAaOj/Bx2CAHZLVRXDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1ec45671908>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data.plot(kind='scatter', x='Population', y='Profit', figsize=(12, 8))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 2.2 梯度下降\n",
    "\n",
    "$$J\\left( \\theta  \\right)=\\frac{1}{2m}\\sum\\limits_{i=1}^{m}{{{\\left( {{h}_{\\theta }}\\left( {{x}^{(i)}} \\right)-{{y}^{(i)}} \\right)}^{2}}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_cost(X, y, theta):\n",
    "    temp = np.power(((X * theta.T) - y), 2)\n",
    "    return np.sum(temp) / (2 * len(X))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.insert(0, 'Ones', 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols = data.shape[1]\n",
    "X = data.iloc[:,:-1]#X是data里的除最后列\n",
    "y = data.iloc[:,cols-1:cols]#y是data最后一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Ones</th>\n",
       "      <th>Population</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>6.1101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>5.5277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>8.5186</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>7.0032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>5.8598</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Ones  Population\n",
       "0     1      6.1101\n",
       "1     1      5.5277\n",
       "2     1      8.5186\n",
       "3     1      7.0032\n",
       "4     1      5.8598"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Profit</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17.5920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.1302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13.6620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11.8540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6.8233</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Profit\n",
       "0  17.5920\n",
       "1   9.1302\n",
       "2  13.6620\n",
       "3  11.8540\n",
       "4   6.8233"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.matrix(X.values)\n",
    "y = np.matrix(y.values)\n",
    "theta = np.matrix(np.array([0,0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((97, 2), (1, 2), (97, 1))"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.shape, theta.shape, y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 学习率初始化为0.01，迭代次数为1500次\n",
    "def gradient_descent(X, y, theta, alpha, iters):\n",
    "    temp = np.matrix(np.zeros(theta.shape))\n",
    "    parameters = int(theta.ravel().shape[1])\n",
    "    cost = np.zeros(iters)\n",
    "    \n",
    "    for i in range(iters):\n",
    "        error = (X * theta.T) - y\n",
    "        \n",
    "        for j in range(parameters):\n",
    "            term = np.multiply(error, X[:,j])\n",
    "            temp[0,j] = theta[0,j] - ((alpha / len(X)) * np.sum(term))\n",
    "            \n",
    "        theta = temp\n",
    "        cost[i] = get_cost(X, y, theta)\n",
    "        \n",
    "    return theta, cost"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![123](../../pic/QQ截图20201021192046.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "32.072733877455676"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_cost(X, y, theta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha = 0.01\n",
    "iters = 1500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-3.63029144,  1.16636235]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g, cost = gradient_descent(X, y, theta, alpha, iters)\n",
    "g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6.73719046,  5.93159357,  5.90115471, ...,  4.48343473,\n",
       "        4.48341145,  4.48338826])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predict1: [[ 0.45197679]]\n",
      "predict2: [[ 4.53424501]]\n"
     ]
    }
   ],
   "source": [
    "predict1 = [1,3.5]*g.T\n",
    "print(\"predict1:\",predict1)\n",
    "predict2 = [1,7]*g.T\n",
    "print(\"predict2:\",predict2)\n",
    "# 预测35000和70000城市规模的小吃摊利润"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtEAAAHwCAYAAABg0TMJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xd8VFX+//HXh2yQKCWi6JrAArYgAgJmVxTLWrGL+LWgYEMRXRVRQhH3t65SjYIoNiyAilgximWxgCJ2MGiUJigqARHBSDFISM7vjzPBgKmQmTvl/Xw8fJDcuXPvZyZg3vfM555jzjlERERERKT66gRdgIiIiIhIrFGIFhERERGpIYVoEREREZEaUogWEREREakhhWgRERERkRpSiBYRERERqSGFaBGJSmbWwsycmf0l9P3rZnZJBM57q5k9Ge7zhM6VYWbzzGy9mV1vZg+a2b8jce5oY2bLzOyEHXzuUWa2qLZrqsZ5E/bnJSIK0SKyE0LBp9DMNpjZKjObaGb1w3Eu59wpzrlJ1axph8JYNY79TzMrCb3e9Wa2yMwu24lDDgBmOucaOOfucc71cc7dXuZcy2un8uoLXUQUhV5jgZl9YGaHR7qOyoQurvY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IiI1E/YQbWb1gReAG5xz64AHgH2B9viR6rvKe55zbrxzLtM5l9mkSZWLxgQiJSWFefPm8eWXX1K3bl0efPDBbR53zlFSUlLj45555pkMGjSowse3D9FpaWk8//zzNT6PiIiIiOyYsIZoM0vGB+jJzrmpAM65Vc65YudcCfAw8I9w1hApRx11FEuWLGHZsmVkZGRw8cUX06ZNG3744QfeeOMNDj/8cDp27Mi5557Lhg0bAPjf//5Hq1at6NixI1OnTt16rIkTJ3LttdcCsGrVKs4++2wOOeQQDjnkED744AMGDRrE0qVLad++PVlZWSxbtow2bdoAvlf8sssuo23btnTo0IGZM2duPWa3bt04+eSTOeCAAxgwYECE3yERERGR+BHO2TkMeBRY4JwbXWb7PqF+aYCzgS93+mQ33ADz5u30YbbRvj3cfXe1dt2yZQuvv/46J598MgBff/01kyZNolOnTvz8888MHTqUt956i912241Ro0YxevRoBgwYwJVXXsmMGTPYf//9Of/888s99vXXX88xxxzDiy++SHFxMRs2bGDkyJF8+eWXzAu95mXLlm3d/7777sPMyMvLY+HChZx00kksXrwYgHnz5pGbm8suu+xCRkYG1113Hc2aNduJN0lEREQkMYVzdo7OQE8gz8xKE+7NQHcza4+f9m4ZcFUYawirwsJC2rdvD/iR6F69erFixQqaN29Op06dAPjoo4+YP38+nTt3BmDz5s0cfvjhLFy4kJYtW3LAAQcA0KNHD8aPH/+nc8yYMYPHH38c8D3YjRo14pdffqmwptmzZ3PdddcB0KpVK5o3b741RB9//PE0atQIgNatW/Pdd98pRIuIiIjsgHDOzjEbKG/KhhrPCV2lao4Y17bSnujt7bbbblu/ds5x4oknMmXKlG32Ke954bbLLrts/TopKYktW7ZEvAYRERGReKBlv8OsU6dOvP/++yxZsgSAjRs3snjxYlq1asWyZctYunQpwJ9Cdqnjjz+eBx54AIDi4mJ+/fVXGjRowPr168vd/6ijjmLy5MkALF68mO+//56MjIzaflkiIiIiCU0hOsyaNGnCxIkT6d69O+3atdvaylGvXj3Gjx/PaaedRseOHdlrr73Kff7YsWOZOXMmbdu25dBDD2X+/PnssccedO7cmTZt2pCVlbXN/tdccw0lJSW0bduW888/n4kTJ24zAi0iIiIiO8+cc0HXUKXMzEw3Z86cbbYtWLCAgw46KKCKpDz6mYiIiEisM7O5zrnMqvbTSLSIiIiISA2Fc3YOEREREZFK5eTmkz19ESsKCklLTSGrSwZdO6QHXVaVFKJFREREJBA5ufkMnppHYVExAPkFhQyemgcQ9UFa7RwiIiIiEojs6Yu2BuhShUXFZE9fFFBF1acQLSIiIiKBWFFQWKPt0UQhWkREREQCkZaaUqPt0UQhegetWbOG9u3b0759e/7617+Snp6+9fvNmzfv1LFffPFFsrOza6XOHj160LJlSw455BAOPPBALrnkElasWFHl80aPHs2mTZtqpQYRERGR8mR1ySAlOWmbbSnJSWR1if6F4nRj4Q7aY489ti7dfeutt1K/fn369++/zT7OOZxz1KlTs2uVs88+u9bqBBgzZgxdu3alpKSE0aNHc9xxx5GXl0dycnKFzxk9ejSXX3459erVq9VaREREREqV3jwYi7NzJMxIdE5uPp1HzqDloFfpPHIGObn5YTnPkiVLaN26NRdddBEHH3wwK1eupHfv3mRmZnLwwQdz2223bd23adOm3HrrrXTo0IF27dqxePFiAB555BFuuOEGwI8k9+3blyOOOIJ9992XF198EfBLgPfp04dWrVpx0kkncfLJJ5OTk1NpbXXq1KF///40btyYN954A6Dc2saMGcNPP/3EUUcdxQknnFDhfiIiIiI7q2uHdN4fdBzfjjyN9wcdFxMBGhIkRJdOn5JfUIjjj+lTwhWkFy5cSL9+/Zg/fz7p6emMHDmSOXPm8Pnnn/Pmm28yf/78rfvuvffe5ObmcsUVVzB69Ohyj/fTTz/x/vvvk5OTw+DBgwF47rnnyM/PZ/78+UycOJEPP/yw2vV17NiRhQsXApRbW79+/dhrr7147733eOuttyrcT0RERCRRJUSIjvT0Kfvttx+ZmX+sFjllyhQ6duxIx44dWbBgwTYBtFu3bgAceuihLFu2rNzjde3aFTOjXbt25Of74D979mzOO+886tSpQ1paGsccc0y16yu71HtltZVV3f1EREREEkFC9ERHevqU3XbbbevXX3/9NWPHjuWTTz4hNTWVHj16bHPD3i677AJAUlISW7ZsKfd4pfvAtgF4R82bN4/TTjutytqq+xpEREREEk1CjEQHOX3KunXraNCgAQ0bNmTlypVMnz69Vo7buXNnnn/+eZxzrFy5klmzZlX5HOccY8aMYc2aNZx44omV1tagQQPWr18f1tcgIiIiEqsSYiQ6q0vGNktKQuSmT+nYsSOtW7emVatWNG/enM6dO9fKcc877zxmzJjBQQcdRPPmzenQoQONGjUqd99+/frxn//8h8LCQg4//HBmzJhBcnJypbX17t2bE044gWbNmvHmm2+G5TWIiIiIxCqrjfaAcMvMzHRz5szZZtuCBQs46KCDqn2MnNz8mJw+pTIbNmygfv36rF69msMOO4yPP/6YJk2aBFZPTX8mIiIiItHGzOY65zKr2i8hRqLBT58S66F5e6eccgrr1q2jqKiI//73v4EGaBEREZFEkjAhOh699957QZcgIiIikpAS4sZCEREREZHaFNMhOhb6uROFfhYiIiKSSGI2RNerV481a9YovEUB5xxr1qyhXr16QZciIiIiEhEx2xPdtGlTli9fzurVq4MuRfAXNU2bNg26DBEREZGIiNkQnZycTMuWLYMuQ0REREQSUMy2c4iIiIiIBCVmR6JFREQkscXjQmoSOxSiRUREJObk5OYzeGoehUXFAOQXFDJ4ah6AgrREhNo5REREJOZkT1+0NUCXKiwqJnv6ooAqkkSjEC0iIiIxZ0VBYY22i9Q2hWgRERGJOWmpKTXaLlLbFKJFREQk5mR1ySAlOWmbbSnJSWR1yQioIkk0urFQREREYk7pzYOanUOCohAtIiIiMalrh3SF5njx4Yfw+efQp0/QlVSb2jlEREREJPKcg5kz4fjj4YgjYOhQ+P33oKuqNoVoEREREYkc5+D11+HII+G442D+fLjrLli4EHbZJejqqk3tHCIiIiISfiUl8NJLMGwYzJ0LzZrBuHFw+eWQEnuzqmgkWkRERETCp7gYpkyBdu2gWzcoKIBHHoElS+Bf/4rJAA0K0SIiIiISDkVFMGECHHQQXHihb+N48knfttGrF9StG3SFO0XtHCIiIiI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HW5Mhbyvx3H8CvpdSui4i9gXOynSlG3s9/+d6/H+IpAnMmWhJag2/AWZExNsjYjPgU/ljANtFxF/lP/87ciUaACuBXfOfH1HidbcA+vOfH11w/BVg85Enp5ReAl4sqHc+Crht5HmSNNEZoiWpBaSU7gX+FbgbuAv4SUppSf7hFcDxEfEQ8C7gB/njZwMXRMQicjPDxZwFXBMRi4HfFxy/HvjU0MLCEc85GpgbEfcDuwDfGst/mySNR5HSyN8SSpJaRb6Txg35dniSpBbhTLQkSZKUkTPRkiRJUkbOREuSJEkZGaIlSZKkjAzRkiRJUkaGaEmSJCkjQ7QkSZKUkSFakiRJyuj/A13qhyQn+ddKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1ec46c32438>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(data.Population.min(), data.Population.max(), 100)\n",
    "f = g[0, 0] + (g[0, 1] * x)\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12,8))\n",
    "ax.plot(x, f, 'r', label='Prediction')\n",
    "ax.scatter(data.Population, data.Profit, label='Traning Data')\n",
    "ax.legend(loc=2)\n",
    "ax.set_xlabel('Population')\n",
    "ax.set_ylabel('Profit')\n",
    "ax.set_title('Predicted Profit vs. Population Size')\n",
    "plt.show()\n",
    "# 原始数据以及拟合的直线"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.4 可视化$J(θ)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Size</th>\n",
       "      <th>Bedrooms</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2104</td>\n",
       "      <td>3</td>\n",
       "      <td>399900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1600</td>\n",
       "      <td>3</td>\n",
       "      <td>329900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2400</td>\n",
       "      <td>3</td>\n",
       "      <td>369000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1416</td>\n",
       "      <td>2</td>\n",
       "      <td>232000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3000</td>\n",
       "      <td>4</td>\n",
       "      <td>539900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Size  Bedrooms   Price\n",
       "0  2104         3  399900\n",
       "1  1600         3  329900\n",
       "2  2400         3  369000\n",
       "3  1416         2  232000\n",
       "4  3000         4  539900"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path =  './data/ex1data2.txt'\n",
    "data2 = pd.read_csv(path, header=None, names=['Size', 'Bedrooms', 'Price'])\n",
    "data2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Size</th>\n",
       "      <th>Bedrooms</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.130010</td>\n",
       "      <td>-0.223675</td>\n",
       "      <td>0.475747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.504190</td>\n",
       "      <td>-0.223675</td>\n",
       "      <td>-0.084074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.502476</td>\n",
       "      <td>-0.223675</td>\n",
       "      <td>0.228626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.735723</td>\n",
       "      <td>-1.537767</td>\n",
       "      <td>-0.867025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.257476</td>\n",
       "      <td>1.090417</td>\n",
       "      <td>1.595389</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Size  Bedrooms     Price\n",
       "0  0.130010 -0.223675  0.475747\n",
       "1 -0.504190 -0.223675 -0.084074\n",
       "2  0.502476 -0.223675  0.228626\n",
       "3 -0.735723 -1.537767 -0.867025\n",
       "4  1.257476  1.090417  1.595389"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2 = (data2 - data2.mean()) / data2.std()\n",
    "data2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ -1.10856950e-16,   8.84042349e-01,  -5.24551809e-02]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 加一列常数项\n",
    "data2.insert(0, 'Ones', 1)\n",
    "\n",
    "# 初始化X和y\n",
    "cols = data2.shape[1]\n",
    "X2 = data2.iloc[:,0:cols-1]\n",
    "y2 = data2.iloc[:,cols-1:cols]\n",
    "\n",
    "# 转换成matrix格式，初始化theta\n",
    "X2 = np.matrix(X2.values)\n",
    "y2 = np.matrix(y2.values)\n",
    "theta2 = np.matrix(np.array([0,0,0]))\n",
    "\n",
    "# 运行梯度下降算法\n",
    "g2, cost2 = gradient_descent(X2, y2, theta2, alpha, iters)\n",
    "g2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 正规方程\n",
    "def normalEqn(X, y):\n",
    "    theta = np.linalg.inv(X.T@X)@X.T@y#X.T@X等价于X.T.dot(X)\n",
    "    return theta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-3.89578088],\n",
       "        [ 1.19303364]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final_theta2=normalEqn(X, y)#这里用的是data1的数据\n",
    "final_theta2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
